"""
洗牌后的每个元素随机出现在每个位置，且概率相同

"""

import random

# 概率相同  O(n)
def self_shuffle(cards):
    for i in range(len(cards)):
        idx = random.randint(i,len(cards)-1)
        cards[i],cards[idx] = cards[idx],cards[i]

    return cards

# A = [i for i in range(0, 10)]

# def test_shuffle(f):
#     result = [[0 for i in range(10)] for j in range(10)]

#     for i in range(100000):
#         A = [i for i in range(0, 10)]
#         f(A)
#         for j in range(len(A)):
#             result[A[j]][j] += 1
        
#     print('\n'.join([''.join(['{:6}'.format(item) for item in row]) 
#           for row in result]))

# test_shuffle(self_shuffle)

